package de.openlaboratory.elib.utilities;

public enum Operation
{
	CREATE("create"),
	READ("read"),
	UPDATE("update"),
	DELETE("delete"),
	LISTALL("listall"),
	NOOP("null");

	  private String text;

	Operation(String text) {
		this.text = text;
	}

	public String getText() {
		return this.text;
	}
	
	/**
	 * Returns an Operation for its String representation. Unlike <b>valueOf</b>
	 * no Exception is thrown if the input String cannot be mapped to any Operation.
	 * In that case <i>NOOP</i> is returned.
	 * @param text
	 * @return Operation from String. <b>NOOP</b> in case of mismatch.
	 */
	public static Operation fromString(String text) {
    if (text != null)
    {
    	for (Operation op : Operation.values())
    	{
    		if (text.equalsIgnoreCase(op.text))
    		{
    			return op;
    		}
		}
    }
    return NOOP;
  }
}
